package com.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.AnnouncesDao;
import com.model.Announces;

@WebServlet("/MakeHomePage")
public class MakeHomePage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public MakeHomePage() {
        super();
    }

	protected void doGet(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        rep.setContentType("text/html;charset=\"UTF-8\"");
      
        
        Writer out = rep.getWriter();
		AnnouncesDao ad=new AnnouncesDao();
		Announces a=new Announces();
		List<Announces> aList=ad.query(a);
		String str="[";
		for (Announces an : aList) {
			//System.out.println(an.getAnnouncesID()+"\t"+an.getAnnouTitle()+"\t"+an.getAnnouBody()+"\t"+an.getFile());
			str+="{\"id\":"+an.getAnnouncesID() +",\"title\":\"" + an.getAnnouTitle() + "\"},"; 
			
		}
		String str1=str.substring(0,str.length()-1);
		str1+="]";
		
		out.write(str1);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
